11. JShell

JShell

ND079 JPND C3 L1 A08 JShell V3

Read-Eval-Print Loop (REPL)

Having access to a simple interactive interface for executing program code makes it easier to experiment and learn about a language. Java 9 introduced a REPL with the program JShell, which you can find in the /bin directory of your JDK installation.

To start JShell, simply type jshell from any command prompt that has access to this directory. If you can run java and javac, you should also be able to run jshell.

Once you've entered JShell, you can type any normal java code to have it immediately executed. Pressing tab will offer code completion suggestions and display javadoc documentation.

Useful Commands

  • /vars** **- Prints a list of all the variables you've declared.
  • /types - Prints all the classes you've defined.
  • /methods - Prints all the methods you've defined.
  • /list - Prints all the source code you've entered.
  • /exit - Closes JShell